<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>单行输入框</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <link rel="stylesheet" href="../formdesign/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="./css/ueditor/site.css">
    <script type="text/javascript" src="../dialogs/internal.js"></script>
    <script type="text/javascript" src="../../../js/jquery/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="../../../js/base/base.js"></script>
    <script type="text/javascript">
        /* Thank you by
         http://www.alt-tag.com/blog/2006/02/ie-dom-bugs/ */
        function createElement(type, name) {
            var element = null;
            try {
                element = document.createElement('<' + type + ' name="' + name + '">');
            } catch (e) {
            }
            if (element == null) {
                element = document.createElement(type);
                element.name = name;
            }
            return element;
        }
    </script>
</head>
<body>
<div class="content">
    <table class="table table-bordered table-striped table-hover">
        <tr>
            <th><span>控件名称</span><span class="label label-important">*</span></th>
            <th  colspan="2"><span>默认值</span></th>
        </tr>
        <tr>
            <td>
                <input type="text" id="orgname" placeholder="必填项">
                <input type="hidden" id="fielid" placeholder="必填项">
            </td>
            </td>

            <td colspan="2"><input type="text" id="orgvalue" placeholder="无则不填"></td>

        </tr>

        <tr>
            <th><span>数据类型</span></th>
            <th><span>对齐方式</span></th>
        </tr>
        <tr>
            <td>
                <select id="orgtype">
                    <option value="text">普通文本</option>
                    <!--<option value="email" disabled>邮箱地址</option>-->
                    <!--<option value="int" disabled>整数</option>-->
                    <!--<option value="float" disabled>小数</option>-->
                    <!--<option value="idcard" disabled>身份证号码</option>-->
                </select>
            </td>
            <td>
                <select id="orgalign">
                    <option value="left">左对齐</option>
                    <option value="center">居中对齐</option>
                    <option value="right">右对齐</option>
                </select>
            </td>
        </tr>
        <tr>
            <th  colspan="2">
                <span>&nbsp;&nbsp;&nbsp;&nbsp;宽&nbsp;&nbsp;X&nbsp;&nbsp;高&nbsp;&nbsp;&nbsp;&&nbsp;&nbsp;&nbsp;字体大小</span>
            </th>
            <!--<th><span>可见性</span></th>-->
        </tr>
        <tr>
            <td  colspan="2">
                <input id="orgwidth" type="text" value="150" class="input-small span1" placeholder="auto"/>
                X
                <input id="orgheight" type="text" value="" class="input-small span1" placeholder="auto"/>
                &
                <input id="orgfontsize" type="text" value="" class="input-small span1" placeholder="auto"/> px

            </td>
            <!--<td>-->
                <!--<label class="checkbox inline"><input id="orghide" type="checkbox"/> 隐藏 </label>-->
            <!--</td>-->
        </tr>

    </table>
</div>
<script type="text/javascript">
    $(function () {

        var dataid = $.getQueryString('dataid');
        var dataNumber=parent.pluginId;
        var oNode = null, thePlugins = 'text';
        if (UE.plugins[thePlugins].editdom) {
            oNode = UE.plugins[thePlugins].editdom;

            var gValue = oNode.value, gName = oNode.getAttribute('name'),
                gTitle = oNode.getAttribute('title').replace(/&quot;/g, "\""),
                gFontSize = oNode.getAttribute('orgfontsize'), gAlign = oNode.getAttribute('orgalign'),
                gWidth = oNode.getAttribute('orgwidth'), gHeight = oNode.getAttribute('orgheight'),
                gType = oNode.getAttribute('orgtype');

            gValue = gValue == null ? '' : gValue;
            gTitle = gTitle == null ? '' : gTitle;
            gName = gName == null ? '' : gName;
            $G('orgvalue').value = gValue;
            $G('fielid').value = gName;
            $G('orgname').value = gTitle;
            if(gWidth != ''){
                $G('orgwidth').value = gWidth;
            }
            $G('orgheight').value = gHeight;
            $G('orgfontsize').value = gFontSize;
            //$G('orgalign').val(gAlign);
        }

        dialog.oncancel = function () {
            if (UE.plugins[thePlugins].editdom) {
                delete UE.plugins[thePlugins].editdom;
            }
        };
        dialog.onok = function () {

            if ($G('orgname').value == '') {
                alert('请输入控件名称');
                return false;
            }
            var gValue = $G('orgvalue').value.replace(/\"/g, "&quot;"), gid = $G('fielid').value,
                gTitle = $G('orgname').value.replace(/\"/g, "&quot;"),
                gFontSize = $G('orgfontsize').value, gAlign = $G('orgalign').value, gWidth = $G('orgwidth').value,
                gHeight = $G('orgheight').value, gType = $G('orgtype').value;

            if (!oNode) {
                try {
                    oNode = createElement('input', 'NEWFIELD');
                    oNode.setAttribute('class', "form_item");
                    oNode.setAttribute('data-type', "text");
                    oNode.setAttribute('type', gType);
                    oNode.setAttribute('title', gTitle);
                    oNode.setAttribute('value', gValue);
                    oNode.setAttribute('name', 'DATA_' + dataNumber);
                    oNode.setAttribute('id', 'DATA_' + dataNumber);
                    oNode.setAttribute('orgfontsize',gFontSize);
                    oNode.setAttribute('orgalign',gAlign);
                    oNode.setAttribute('orgwidth',gWidth);
                    oNode.setAttribute('orgheight',gHeight);

//                   if ($G('orghide').checked) {
//                        oNode.setAttribute('orghidden', 1);
//                    } else {
//                        oNode.setAttribute('orghidden', 0);
//                    }
                    if (gFontSize != '') {
                        oNode.style.fontSize = gFontSize + 'px';
                    }
                    if (gAlign != '') {
                        //style += 'text-align:' + gAlign + ';';
                        oNode.style.textAlign = gAlign;
                        oNode.setAttribute('align', gAlign);
                    }

                    if (gHeight != '') {
                        oNode.style.height = gHeight + 'px';
                    }
                    if (gWidth != '') {
                        oNode.style.width = gWidth + 'px';
                    }
                    editor.execCommand('insertHtml', oNode.outerHTML);
                } catch (e) {
                    try {
                        editor.execCommand('error');
                    } catch (e) {
                        alert('控件异常，请联系技术支持');
                    }
                    return false;
                }
            } else {
                oNode.setAttribute('class', "form_item");
                oNode.setAttribute('data-type', "text");
                oNode.setAttribute('title', gTitle);
                oNode.setAttribute('value', $G('orgvalue').value);
                oNode.setAttribute('name', gid);
                oNode.setAttribute('id', gid);
                oNode.setAttribute('type', gType);
                oNode.setAttribute('orgfontsize',gFontSize);
                oNode.setAttribute('orgalign',gAlign);
                oNode.setAttribute('orgwidth',gWidth);
                oNode.setAttribute('orgheight',gHeight);

//                if ($G('orghide').checked) {
//                    oNode.setAttribute('orghidden', 1);
//                } else {
//                    oNode.setAttribute('orghidden', 0);
//                }
//	        if ( $G('fieldflow').checked ) {
//	            oNode.setAttribute('fieldflow',1);
//	        } else {
//	            oNode.setAttribute('fieldflow',0);
//	        }
                if (gFontSize != '') {
                    oNode.style.fontSize = gFontSize + 'px';
                    //oNode.setAttribute('orgfontsize',gFontSize );
                } else {
                    oNode.style.fontSize = '';
                    // oNode.setAttribute('orgfontsize', '');
                }
                if (gAlign != '') {
                    oNode.style.textAlign = gAlign;
                    // oNode.setAttribute('orgalign',gAlign );
                } else {
                    // oNode.setAttribute('orgalign', '');
                }
                if (gWidth != '') {
                    oNode.style.width = gWidth + 'px';
                    //oNode.setAttribute('orgwidth',gWidth );
                } else {
                    oNode.style.width = '';
                    // oNode.setAttribute('orgwidth', '');
                }
                if (gHeight != '') {
                    oNode.style.height = gHeight + 'px';
                    // oNode.setAttribute('orgheight',gHeight );
                } else {
                    oNode.style.height = '';
                    // oNode.setAttribute('orgheight', '');
                }
                if (gType != '') {
                    // oNode.setAttribute('orgtype',gType );
                } else {
                    // oNode.setAttribute('orgtype', '');
                }
                delete UE.plugins[thePlugins].editdom;
            }
        };
    });

</script>
</body>
</html>